using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SAInterfaceLibrary;

namespace ROOTBuildProjectCreatorSA
{
    /// <summary>
    /// Allows the user to choose a template to load.
    /// </summary>
    public partial class LoadConfigTemplateDialog : Form
    {
        private string _template_name;

        /// <summary>
        /// Get or set the name of the template.
        /// </summary>
        public string TemplateName
        {
            get { return _template_name; }
            set { _template_name = value; }
        }


        public LoadConfigTemplateDialog()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Load up the combo box with all availible template names.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            ///
            /// Get a list of all possible specs for later use!
            /// 

            int selected_index = 0;
            int index = 0;
            List<string> allNames = new List<string>();
            foreach (var n in ProjectBuildConfigSpec.AllKnownConfigNames())
            {
                allNames.Add(n);
            }
            allNames.Sort();
            foreach (string relname in allNames)
            {
                cbTemplateChoice.Items.Add(relname);
                if (relname == TemplateName)
                {
                    selected_index = index;
                }
                index = index + 1;
            }
            cbTemplateChoice.Text = TemplateName;

            ///
            /// Make sure selected index isn't totally bogus!
            /// 

            if (selected_index == 0)
            {
                if (index > 0)
                {
                    selected_index = 1;
                }
            }
            if (selected_index != 0)
            {
                cbTemplateChoice.SelectedIndex = selected_index;
            }
        }

        /// <summary>
        /// See if the user choose something other than what we have...
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bOK_Click(object sender, EventArgs e)
        {
            string selected_item = (string)cbTemplateChoice.SelectedItem;
            TemplateName = selected_item;
        }
    }
}